#include <iostream>
#include <exception>

using namespace std;

class Base{
	virtual void dummy(){}
};

class Derived: public Base{
	int a;
};

class Another{
	int b;
};

static void dynamic_cast_demo(){
	try{
		Base* pbase = new Base();
		Base* pderived = new Derived();

		Derived *pd;

		pd = dynamic_cast<Derived*>(pderived);
		if (pd == nullptr){
			cout << "NUll pointer on first type-cast.\n";
		}
		pd = dynamic_cast<Derived*>(pbase);
		if (pd == nullptr){
			cout << "NUll pointer on second type-case.\n";
		}
	}catch(exception& e){
		cout << "Exception: " << e.what() << endl;
	}
}

static void static_cast_demo(){
	Base* base = new Base();
	Derived *derived = static_cast<Derived*>(base);
	cout << "static cast: " << derived << endl;
}

static void reinterpret_cast_demo(){
	Base* base = new Base();
	long base_l = (long)base;
	Base* another = reinterpret_cast<Base*>(base_l);
	cout << "base == aother = " << (base == another) << endl;
}


int main(){
	dynamic_cast_demo();
	static_cast_demo();
	reinterpret_cast_demo();
	return 0;
}
